package com.xiaren.application;

import com.xiaren.biz.FrameBiz;
import com.xiaren.common.IConstant;
import com.xiaren.common.ObjectConstant;
import com.xiaren.ui.MainFrame;
import com.xiaren.ui.dialog.TitleWindow;
import com.xiaren.util.SystemTrayUtil;
import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.theme.SubstanceTerracottaTheme;

import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import java.awt.*;
import java.io.*;
import java.util.Enumeration;


/**
 * 程序入口
 *
 * @author xiaren<br/>
 * @主页 http://www.leaf123.cn/
 * @邮箱 xia5523@qq.com
 */
public class InApplication {

    /**
     * 待开发功能
     * 1、加密             ok
     * 2、默认设置字体微软雅黑 ok
     * 3、设置斜体，下划线字体     ok
     * 4、设置光标处字体大小等属性设置     （暂时不好处理）
     * 5、窗口最大化之后，关闭窗口，则显示的为未保存状态，并且事件有问题。       ok
     * 6、日志
     * 7、去掉ping的那个输入框       ok
     * 8、添加启动nginx的装置
     * 9、截屏
     * 10、处理如何正确打包jar       ok
     * 11、文本里面剪切，后退前进功能改进   ok
     * 12、密码文件进行加密
     * 13、目前编码格式没搞定         ok
     *
     * @param args
     */

    public static void main(String[] args) throws Exception {
//        try {
//            javax.swing.UIManager.LookAndFeelInfo[] installedLookAndFeels = javax.swing.UIManager.getInstalledLookAndFeels();
//            for (int idx = 0; idx < installedLookAndFeels.length; idx++) {
//                if ("Nimbus".equals(installedLookAndFeels[idx].getName())) {
//                    javax.swing.UIManager.setLookAndFeel(installedLookAndFeels[idx].getClassName());
//                    break;
//                }
//                if ("Windows".equals(installedLookAndFeels[idx].getName())) {
//                    javax.swing.UIManager.setLookAndFeel(installedLookAndFeels[idx].getClassName());
//                    break;
//                }
//            }
//        } catch (Exception ex) {
//            ex.printStackTrace();
//        }

        loadLook();

        // 设置全局字体
//        initGlobalFontSetting(new Font("隶书", Font.PLAIN, 14));

        // 正式启动
        ObjectConstant.mainFrame = new MainFrame(
                IConstant.JFRAME_TITLE);
        ObjectConstant.frameBiz = new FrameBiz();
        ObjectConstant.frameBiz.init();
        SystemTrayUtil.addSystemTray(); // 右下角的托盘
        TitleWindow.creatTitleWindow(); // 右上角的显示图标
    }


    //设置全局字体
    // http://www.xuebuyuan.com/173172.html
    public static void initGlobalFontSetting(Font fnt) {
        FontUIResource fontRes = new FontUIResource(fnt);
        for (Enumeration keys = UIManager.getDefaults().keys(); keys.hasMoreElements(); ) {
            Object key = keys.nextElement();
            Object value = UIManager.get(key);
            if (value instanceof FontUIResource)
                UIManager.put(key, fontRes);
        }
    }

    /**
     * 用于第三方皮肤控件
     *
     * @throws Exception
     */
    private static void loadLook() throws Exception {
        UIManager
                .setLookAndFeel("org.jvnet.substance.skin.SubstanceGreenMagicLookAndFeel");
        JFrame.setDefaultLookAndFeelDecorated(true);
        JDialog.setDefaultLookAndFeelDecorated(true);
        SubstanceLookAndFeel
                .setCurrentTheme(new SubstanceTerracottaTheme());

		/*
     * UIManager.setLookAndFeel(new SubstanceLookAndFeel());
	 *
	 * //UIManager.setLookAndFeel(
	 * "org.jvnet.substance.skin.SubstanceBusinessLookAndFeel");
	 *
	 * //UIManager.setLookAndFeel(
	 * "org.jvnet.substance.skin.SubstanceOfficeSilver2007LookAndFeel");
	 *
	 * //UIManager.setLookAndFeel(
	 * "org.jvnet.substance.skin.SubstanceSaharaLookAndFeel");
	 *
	 * //UIManager.setLookAndFeel(
	 * "org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel");
	 *
	 * UIManager.setLookAndFeel(
	 * "org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel");
	 */

        /**
         * 在C:\Program Files
         * (x86)\Java\jre6\lib\ext下面添加了substance.jar,kbmonitor.jar,KBMonitor_C.dll
         *
         *
         *
         *
         *
         */


    }


}
